package be.jprojects.subscription.gui;

import java.awt.*;
import java.awt.geom.Rectangle2D;
import javax.swing.*;

public class StatusBar extends JPanel {
	private String text;
	public enum Status {error, wait, nothing};
	public Status currentStatus;
	
	public static final ImageIcon WAITICON = new ImageIcon("Resources/wait.png");
	public static final ImageIcon ERRORICON = new ImageIcon("Resources/error.gif");
	
	
	public StatusBar() {
		setPreferredSize(new Dimension(999999,20));
	}
	
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		GradientPaint redtowhite = new GradientPaint(0, 0, new Color(251,251,251), 0, this.getHeight(), new Color(226,226,226));
		g2.setPaint(redtowhite);
		g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
		
		if (currentStatus == Status.wait) {
			g2.drawImage(StatusBar.WAITICON.getImage(),2,2,null);
			g2.setColor(new Color(153,51,51));
		} else if (currentStatus == Status.error) {
			g2.drawImage(StatusBar.ERRORICON.getImage(),2,2,null);
			g2.setColor(new Color(100,100,100));
		} else {
			g2.clearRect(1, 1, getWidth(), getHeight());
		}
		if (text!=null)
			g2.drawString(text, 25, 14);
	}

	public String getText() {
		return text;
	}

	public void setText(String text, Status status) {
		this.text = text;
		currentStatus = status;
		super.repaint();
	}
}
